home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Misc / emu / Wzonka-Lad.lha / Wzonka-Lad / src / scanline_aga_I.s < prev    next >
Text File  |  1999-05-04  |  15KB  |  536 lines

  1.  
  2. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  3. ;        scanline drawer
  4. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  5.  
  6. scanline_aga:    move.b    output_bit,d7
  7.         cmp.b    frame_update,d7
  8.         bne.w    no_scan_aga            ;no draw.
  9.  
  10.         move.l    aga_map_inactive,d6
  11.         cmp.l    aga_map_I,d6
  12.         beq.s    wait_Ix
  13. wait_IIx:    tst.b    visual_frame
  14.         bne.s    wait_IIx
  15.         bra.s    wait_donex
  16. wait_Ix:    tst.b    visual_frame
  17.         beq.s    wait_Ix
  18.  
  19. wait_donex:    cmp.l    #144,gb_scanlines        ;drawing time?
  20.         beq.w    swap_aga_buffex            ;yes!!!
  21.         bgt.w    no_scan_aga            ;no!
  22.  
  23.         move.l    gb_memory,a6
  24.         add.l    #$ff40,a6            ;a6 = lcd control.
  25.         moveq.l    #0,d6
  26.         move.b    (a6),d6                ;d6 = lcd control byte.
  27.         btst    #7,d6                ;lcd operation?
  28.         beq.s    no_scan_aga            ;no. quit.
  29.         move.l    d6,lcd_control            ;store the byte.
  30.  
  31.         bsr.w    push_z80
  32.  
  33.         clr.b    aga_spr_amount            ;zero sprites done.
  34.         bsr.w    scan_aga_sprs            ;do the sprites.
  35.         move.l    aga_sprs_inactive,a5        ;a5 = signal data.
  36.         add.l    gb_scanlines,a5
  37.         move.b    aga_spr_amount,(a5)        ;set the signal.
  38.  
  39.         bsr.w    scan_aga_bg            ;do the background.
  40.         bsr.w    scan_aga_win            ;do the window.
  41.  
  42.         bsr.w    pull_z80
  43. no_scan_aga:    rts                    ;exit.
  44.  
  45. swap_aga_buffex:move.l    copper_inactive,d7
  46.         cmp.l    copper_I,d7
  47.         beq.w    copper_I_in
  48.  
  49. copper_II_in:    bsr.w    update_aga_pal
  50.         move.l    copper_I,copper_inactive
  51.         move.l    aga_map_I,aga_map_inactive
  52.         move.l    aga_ro_list_I,aga_ro_inactive
  53.         move.l    aga_sprs_cI,aga_sprs_inactive
  54.         move.l    aga_sprs_cxI,aga_sprs_inactive_x
  55.         move.l    #bg_scroll_y_I,bg_scroll_inactive
  56.         move.l    #aga_spr_Ia,aga_spr_inactive_pointer
  57.         rts
  58.  
  59. copper_I_in:    bsr.w    update_aga_pal
  60.         move.l    copper_II,copper_inactive
  61.         move.l    aga_map_II,aga_map_inactive
  62.         move.l    aga_ro_list_II,aga_ro_inactive
  63.         move.l    aga_sprs_cII,aga_sprs_inactive
  64.         move.l    aga_sprs_cxII,aga_sprs_inactive_x
  65.         move.l    #bg_scroll_y_II,bg_scroll_inactive
  66.         move.l    #aga_spr_Ib,aga_spr_inactive_pointer
  67.         rts
  68.  
  69. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  70. ;        update AGA h/w palette
  71. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  72.  
  73. update_aga_pal:    movem.l    a4/d0,-(SP)
  74.  
  75.         move.l    gb_memory,a4
  76.         add.l    #$ff47,a4            ;bgrdpal (background palette).
  77.         move.l    aga_col_bg,a5            ;a5 = colour table.
  78.         move.l    aga_hw_spr_cI,a6        ;output = sprite palette.
  79.  
  80.         moveq.l    #0,d7
  81.         move.b    (a4),d0                ;d0 = palette byte.
  82.         move.b    aga_palette_byte,d7        ;last frame's palette.
  83.         move.b    d0,aga_palette_byte
  84.         lsl.w    #4,d7
  85.         add.l    d7,a5
  86.         moveq.l    #4-1,d0
  87. update_aga_palc:move.l    (a5)+,d7
  88.         move.w    d7,10(a6)
  89.         move.w    d7,74(a6)
  90.         move.w    d7,138(a6)
  91.         move.w    d7,202(a6)
  92.         swap    d7
  93.         move.w    d7,2(a6)
  94.         move.w    d7,66(a6)
  95.         move.w    d7,130(a6)
  96.         move.w    d7,194(a6)
  97.         add.l    #16,a6
  98.         dbra    d0,update_aga_palc
  99.  
  100.         move.l    aga_col_bg,a5            ;a5 = colour table.
  101.         move.l    aga_col_cI,a6            ;a6 = output.
  102.         moveq.l    #3-1,d6
  103. next_aga_col:    moveq.l    #0,d7
  104.         move.b    (a4)+,d7            ;d7 = palette byte.
  105.         lsl.w    #4,d7
  106.         add.l    d7,a5
  107.  
  108.         move.w    (a5)+,2(a6)            ;c0.
  109.         move.w    (a5)+,10(a6)
  110.         move.w    (a5)+,18(a6)            ;c1.
  111.         move.w    (a5)+,26(a6)
  112.         move.w    (a5)+,34(a6)            ;c2.
  113.         move.w    (a5)+,42(a6)
  114.         move.w    (a5)+,50(a6)            ;c3.
  115.         move.w    (a5),58(a6)
  116.         add.l    #16*4,a6
  117.         move.l    aga_col_sprs,a5            ;new palette.
  118.         dbra    d6,next_aga_col
  119.  
  120.         movem.l    (SP)+,a4/d0
  121.         rts
  122.  
  123. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  124. ;        execute the background copying
  125. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  126.  
  127. scan_aga_bg:    move.l    lcd_control,d0            ;d0 = lcd control byte.
  128.         btst    #0,d0                ;background display?
  129.         beq.w    scan_aga_bgy            ;no. quit.
  130.  
  131.         move.l    gb_memory,a0            ;a0 = the fixed 16bit
  132.         move.l    a0,a1                ;memory area.
  133.         add.l    #$ff42,a1
  134.         moveq.l    #0,d2
  135.         move.b    (a1)+,d2            ;d2 = bg scroll y.
  136.         moveq.l    #0,d3
  137.         move.b    (a1),d3                ;d3 = bg scroll x.
  138.  
  139.         move.l    d0,d1                ;d1 = the control byte.
  140.         and.b    #%1000,d0            ;d0 = background tiles.
  141.         lsl.w    #7,d0                ;0/1 * 1024.
  142.         lea    (a0,d0.l),a1
  143.         add.l    #$9800,a1            ;tile position.
  144.                             ;a1 = input tiles.
  145.         and.b    #%10000,d1            ;d1 = background tile
  146.         move.l    d1,d7                ;datas. 0/1 * 2048.
  147.         lsl.b    #3,d7                ;d7 = tile adder (signed/
  148.         bchg    #7,d7                ;unsigned).
  149.         move.l    d7,tile_adder
  150.         lsl.w    #7,d1
  151.         move.l    a0,a2
  152.         add.l    #$8800,a2            ;tile data position.
  153.         sub.l    d1,a2                ;selected position.
  154.                             ;a2 = input tile datas.
  155.         move.l    a2,gb_tiles
  156.  
  157. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  158. ;        copy background data
  159. ;        INPUT:
  160. ;        d2    = background scroll y.
  161. ;        d3    = background scroll x.
  162. ;        a1    = tiles.
  163. ;        a2    = tile datas.
  164. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  165.  
  166.         move.l    gb_scanlines,d7
  167.         add.l    d7,d2                ;y = y start + y position.
  168.         move.b    d2,d4
  169.         lsr.w    #3,d2                ;d2 = number of rows
  170.                             ;to be skipped.
  171.         and.l    #%11111,d2            ;stay inside the range.
  172.  
  173.         lsl.w    #5,d2                ;d2 = d2 * 32 (start y).
  174.         add.l    d2,a1                ;y of tiles = done.
  175.  
  176.         move.l    d3,d5
  177.         lsr.w    #3,d3                ;d3 = x start.
  178.         subq.w    #1,d3                ;one before.
  179.         and.l    #%11111,d3            ;stay inside the range.
  180.         move.l    d3,d6                ;when d6 = 32 then back
  181.                             ;to x = 0.
  182.         and.b    #%111,d5
  183.         moveq.l    #8,d0
  184.         and.l    #%111,d4            ;d4 = y pixel scroll (0-7).
  185.         sub.b    d5,d0
  186.  
  187.         move.l    aga_ro_inactive,a0
  188.         move.b    d0,(a0,d7.l)            ;new shift value.
  189.         move.l    d0,gb_x                ;save for the window.
  190.  
  191. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  192. ;        copy 160x1
  193. ;        INPUT:
  194. ;        d4    = background scroll y.
  195. ;        d6    = (background start x) / 8.
  196. ;        d7    = gb_scanlines.
  197. ;        a1    = tiles.
  198. ;        a2    = tile datas.
  199. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  200.  
  201.         move.l    aga_map_inactive,a0
  202.         move.l    d7,d5
  203.         lsl.w    #8,d7
  204.         lsl.w    #6,d5
  205.         add.l    d7,a0                ;256 + 64 = 320.
  206.         add.l    d5,a0                ;y position fix.
  207.         add.l    #64/8-2,a0            ;h/w scroll fix.
  208.         lsl.b    #1,d4                ;d4 = d4 * 2.
  209.         lea    40(a0),a3            ;bitmap (output p1).
  210.         add.l    d4,a2                ;correct line position added.
  211.         move.l    tile_adder,d4            ;speed up.
  212.         moveq.l    #0,d1                ;clear (for .W usage).
  213.  
  214. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  215. ;        copy 160x1 area
  216. ;        INPUT:
  217. ;        d4    = tile adder.
  218. ;        d6    = (background start x) / 8.
  219. ;        a0    = bitmap (output p0).
  220. ;        a1    = tiles.
  221. ;        a2    = tile datas.
  222. ;        a3    = bitmap (output p1).
  223. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  224.  
  225.         move.w    d4,d1
  226.         add.b    (a1,d6.l),d1            ;d1 = left tile.
  227.         lsl.w    #4,d1                ;d1 = d1 * 16.
  228.         addq.b    #1,d6
  229.         move.w    (a2,d1.l),d5            ;d5 = left tile data.
  230.  
  231.         move.b    d5,d2                ;d2 = plane 1.
  232.         and.b    #%11111,d6
  233.         lsr.w    #8,d5                ;d5 = plane 0.
  234.  
  235.         move.w    d4,d1
  236.         lsl.w    #8,d5
  237.         add.b    (a1,d6.l),d1            ;d1 = left tile.
  238.         lsl.w    #8,d2
  239.         lsl.w    #4,d1                ;d1 = d1 * 16.
  240.         addq.b    #1,d6
  241.         move.w    (a2,d1.l),d0            ;d0 = left tile data.
  242.  
  243.         move.b    d0,d2                ;d2 = plane 1.
  244.         move.w    d2,(a3)+            ;p1 write.
  245.         and.b    #%11111,d6
  246.         lsr.w    #8,d0
  247.         move.b    d0,d5                ;d5 = plane 0.
  248.         move.w    d5,(a0)+            ;p0 write.
  249.  
  250.         moveq.l    #20/4-1,d7            ;d7 = 4x blocks.
  251.         moveq.l    #4-1,d3
  252. block_read:    move.w    d4,d1
  253.         lsl.l    #8,d5
  254.         add.b    (a1,d6.l),d1            ;d1 = left tile.
  255.         lsl.l    #8,d2
  256. block_next:    lsl.w    #4,d1                ;d1 = d1 * 16.
  257.         addq.b    #1,d6
  258.         move.w    (a2,d1.l),d0            ;d0 = left tile data.
  259.  
  260.         move.b    d0,d2                ;d2 = plane 1.
  261.         and.b    #%11111,d6
  262.         lsr.w    #8,d0
  263.         move.b    d0,d5                ;d5 = plane 0.
  264.         dbra    d3,block_read
  265.  
  266.         move.l    d5,(a0)+            ;p0 write.
  267.         move.w    d4,d1
  268.         move.l    d2,(a3)+            ;p1 write.
  269.         moveq.l    #4-1,d3
  270.         add.b    (a1,d6.l),d1
  271.         dbra    d7,block_next            ;two pipe loop.
  272. scan_aga_bgy:    rts                    ;exit background drawing.
  273.  
  274. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  275. ;        draw a scanline of the window
  276. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  277.  
  278. scan_aga_win:    move.l    lcd_control,d3            ;d3 = lcd control byte.
  279.         btst    #5,d3                ;window display?
  280.         beq.w    scan_aga_wxt            ;nope.
  281.         btst    #0,d3
  282.         beq.w    scan_aga_wxt
  283.  
  284.         move.l    gb_memory,a0            ;a0 = the fixed 16bit
  285.         move.l    a0,a2
  286.  
  287.         moveq.l    #0,d0
  288.         add.l    #$ff4a,a2            ;a2 = window y position.
  289.         move.b    (a2)+,d0            ;d0 = window y pos ($ff4A).
  290.         move.l    gb_scanlines,d2            ;d2 = the current scanline.
  291.         cmp.w    d0,d2
  292.         blt.w    scan_aga_wxt            ;window not achieved, yet.
  293.  
  294.         moveq.l    #0,d1                ;position fix.
  295.         move.b    (a2),d1                ;d1 = window x pos ($ff4B).
  296.         subq.w    #7,d1                ;x position fix.
  297.         bge.s    win_aga_ok
  298.         clr.w    d1
  299. win_aga_ok:    cmp.w    #160,d1
  300.         bge.w    scan_aga_wxt            ;right out!
  301.  
  302.         addq.l    #8,d1                ;position fixing.
  303.         sub.l    gb_x,d1                ;apply h/w shifter.
  304.         add.l    #$9800,a0            ;window tiles.
  305.         and.b    #%1000000,d3            ;d3 = tile position.
  306.         lsl.w    #4,d3                ;d3 = 0/1 * 1024.
  307.         add.l    d3,a0                ;a0 = window tiles.
  308.  
  309.         move.l    gb_tiles,a1
  310.  
  311. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  312. ;        INPUT:
  313. ;        a0    = window tiles.
  314. ;        a1    = window tile pattern table.
  315. ;        d0    = window y position.
  316. ;        d1    = window x position.
  317. ;        d2    = gb scanline.
  318. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  319.  
  320.         move.l    d2,d3
  321.         sub.l    d0,d2                ;d2 = delta y in window.
  322.         move.l    d2,d6                ;d6 = y in window.
  323.         move.l    d1,d7                ;d7 = window x position.
  324.         lsr.w    #3,d6                ;d6 = y in bytes.
  325.         lsr.w    #3,d7                ;d7 = x in bytes.
  326.         lsl.w    #5,d6                ;d6 = y in gb rows.
  327.  
  328.         add.l    d6,a0                ;rows added.
  329.         move.l    d3,d4
  330.         lsl.w    #8,d3
  331.         lsl.w    #6,d4
  332.         add.l    d4,d3                ;d3 = y * 40*8 = y * 320.
  333.         move.l    aga_map_inactive,a3
  334.         addq.l    #64/8-1,d3            ;aga h/w position fix.
  335.         add.l    d7,d3                ;d3 = x and y.
  336.         add.l    d3,a3                ;a3 = output bg  (p0).
  337.  
  338.         and.l    #%111,d2            ;d2 = scanline adder.
  339.         moveq.l    #160/8+2,d3
  340.         lsl.b    #1,d2                ;data size fix.
  341.         sub.b    d7,d3                ;d3 = delta x in bytes.
  342.         ble.s    scan_aga_wxt            ;too little bytes!
  343.         and.b    #%111,d1            ;d1 = x right shifter.
  344.  
  345. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  346. ;        INPUT:
  347. ;        d1    = x pixels to right shifter.
  348. ;        d2    = the scanline adder.
  349. ;        d3    = delta x in bytes.
  350. ;        a0    = window tiles.
  351. ;        a1    = window tile pattern table.
  352. ;        a3    = background plane 0.
  353. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  354.  
  355.         subq.w    #1,d3                ;dbra correction.
  356.         add.l    d2,a1                ;y inside the block.
  357.         moveq.l    #320/8,d0            ;a speedup.
  358.         moveq.l    #320/8-1,d7            ;         .
  359.         move.l    tile_adder,d2            ;         .
  360.         move.w    #$00ff,d6
  361.         moveq.l    #0,d5
  362.         ror.w    d1,d6                ;solid mask.
  363.  
  364. scan_aga_solid:    move.w    d2,d5
  365.         add.b    (a0)+,d5
  366.         lsl.w    #4,d5
  367.         move.w    (a1,d5.l),d4            ;d4 = data.
  368.  
  369.         move.b    d4,d5                ;d5 = 1.B.
  370.         and.w    d6,(a3)
  371.         clr.b    d4
  372.         lsl.w    #8,d5
  373.         lsr.w    d1,d4                ;shift data.
  374.  
  375.         or.w    d4,(a3)
  376.         add.l    d0,a3
  377.         and.w    d6,(a3)
  378.         lsr.w    d1,d5
  379.         or.w    d5,(a3)
  380.         sub.l    d7,a3
  381.         dbra    d3,scan_aga_solid        ;next byte.
  382. scan_aga_wxt:    rts
  383.  
  384. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  385. ;        do the sprites
  386. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  387.  
  388. scan_aga_sprs:    move.l    aga_sprs_inactive,a0
  389.         move.l    gb_scanlines,d7
  390.         add.l    d7,a0
  391.         tst.b    (a0)
  392.         beq.s    empty_spr_done            ;no sprites here.
  393.         move.l    aga_map_inactive,a1
  394.         move.l    d7,d3
  395.         lsl.w    #8,d7
  396.         lsl.w    #6,d3
  397.         add.l    d3,d7                ;d7 = d7 * 40 * 8.
  398.         add.l    d7,a1                ;y position fixed.
  399.         moveq.l    #40,d3
  400.         add.l    #40*4,a1            ;p0.
  401.         lea    (a1,d3.l),a2            ; 1.
  402.         lea    (a2,d3.l),a3            ; 2.
  403.         lea    (a3,d3.l),a4            ; 3.
  404.         moveq.l    #(160+64)/8/4-1,d1
  405. empty_spr_do:    clr.l    (a1)+
  406.         clr.l    (a2)+
  407.         clr.l    (a3)+
  408.         clr.l    (a4)+
  409.         dbra    d1,empty_spr_do            ;clear this scanline.
  410.         clr.b    (a0)                ;emptied.
  411.  
  412. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  413. ;        first fo the sprites beyond the window
  414. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  415.  
  416. empty_spr_done:    move.l    lcd_control,d1            ;d1 = lcd control byte.
  417.         btst    #1,d1                ;sprites off?
  418.         beq.w    aga_spr_exit            ;yes.
  419.         btst    #2,d1                ;sprite size?
  420.         bne.w    sspr_aga_n8x16            ;8x16.
  421.  
  422. sspr_aga_n8x8:    move.l    #8-1,sprite_y            ;a coming compare fixed
  423.         move.b    #$ff,sprite_mask
  424.         bra.s    sspr_aga_begin            ;value.
  425. sspr_aga_n8x16:    move.l    #16-1,sprite_y
  426.         move.b    #$fe,sprite_mask
  427.  
  428. sspr_aga_begin:    move.l    gb_memory,a0
  429.         move.l    a0,a1
  430.         add.l    #$fe00+40*4,a0            ;a0 = sprite attribute table.
  431.         add.l    #$8000,a1            ;a1 = sprite pattern table.
  432.         moveq.l    #40-1,d0            ;d0 = number of sprites.
  433.  
  434. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  435. ;        sprite size 8xq, q=8/16.
  436. ;        INPUT:
  437. ;        d0    = number of sprites.
  438. ;        a0    = sprite attribute table.
  439. ;        a1    = sprite pattern table.
  440. ;        a3    = sprite output planes.
  441. ;««««««««««««««««««««««««««««««««««««««««««««««»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
  442.  
  443. sspr_aga_c8xq:    cmp.b    #10,aga_spr_amount        ;max sprites (h/w limit)?
  444.         beq.w    aga_spr_exit            ;yes. exit.
  445.  
  446.         move.l    -(a0),d1            ;d1 = y.B, x.B, gfx.B, flags.B.
  447.         swap    d1                ;d1 = gfx.B, flags.B, y.B, x.B.
  448.         moveq.l    #0,d2
  449.         move.b    d1,d2                ;d2 = x.B.
  450.         cmp.w    #160+8,d2            ;crossed the right border?
  451.         bge.w    aga_next_spr            ;yes.
  452.  
  453.         moveq.l    #0,d3
  454.         ror.w    #8,d1                ;d1 = gfx.B, flags.B, x.B, y.B.
  455.         move.b    d1,d3                ;d3 = y.B.
  456.  
  457.         move.l    gb_scanlines,d4            ;d4 = the scanline number.
  458.         move.l    d4,d5
  459.         add.b    #16,d4                ;y position fix.
  460.         move.l    d4,d6
  461.         cmp.w    d3,d4                ;scanline lower?
  462.         blt.w    aga_next_spr            ;yes.
  463.         move.l    d3,d7
  464.         add.l    sprite_y,d7
  465.         cmp.w    d7,d4                ;scanline higher?
  466.         bgt.w    aga_next_spr            ;yes.
  467.  
  468.         move.l    d5,d7
  469.         lsl.w    #8,d7
  470.         lsl.w    #6,d5
  471.         add.w    d7,d5                ;y on screen.
  472.         move.l    aga_map_inactive,a4
  473.         add.l    #64/8-1,d5            ;aga h/w position fix.
  474.         sub.l    d3,d6                ;d6 = y inside the sprite.
  475.         add.l    d5,a4                ;a4 = output spr (p0).
  476.  
  477.         rol.l    #8,d1                ;d1 = flags.B, x.B, y.B, gfx.B.
  478.         and.b    sprite_mask,d1
  479.         move.b    d1,d3                ;d3 = gfx.B.
  480.         lsl.w    #4,d3                ;d3 = d3 * 16.
  481.  
  482.         rol.l    #8,d1                ;d1 = x.B, y.B, gfx.B, flags.B.
  483.         btst    #6,d1                ;y flipped?
  484.         beq.s    no_aga_spr_yf            ;nope.
  485.         move.b    sprite_y+3,d4
  486.         eor.b    d4,d6                ;y flipped.
  487.  
  488. no_aga_spr_yf:    lsl.b    #1,d6                ;y = y * 2 (for data).
  489.         moveq.l    #0,d7
  490.         add.l    d6,d3
  491.         move.w    (a1,d3.l),d7            ;d7 = pattern data.
  492.         beq.w    aga_next_spr            ;empty sprite.
  493.  
  494.         addq.b    #1,aga_spr_amount        ;one sprite more.
  495.  
  496.         btst    #5,d1                ;x flipped?
  497.         beq.s    no_aga_spr_xf            ;no.
  498.         move.l    x_flip_table,a3
  499.         move.w    (a3,d7.l*2),d7            ;fetch the x flipped data.
  500.  
  501. no_aga_spr_xf:    move.l    d2,d4                ;d4 = x.B.
  502.         lsr.b    #3,d4                ;d4 = x.B / 8.
  503.         add.l    d4,a4                ;y and x fixed.
  504.  
  505.         btst    #4,d1                ;which palette?
  506.         bne.s    aga_spr_p1
  507. aga_spr_p0:    add.l    #40*4,a4            ;output (data).
  508.         lea    80(a4),a5            ;       (mask).
  509.         bra.s    aga_spr_out
  510. aga_spr_p1:    lea    160(a4),a5            ;output (mask).
  511.         add.l    #40*6,a4            ;       (data).
  512.  
  513. aga_spr_out:    moveq.l    #0,d3
  514.         move.b    d7,d3                ;d3 = 1.B.
  515.         lsr.w    #8,d7                ;d7 = 0.B.
  516.         moveq.l    #8,d1
  517.         and.b    #%111,d2            ;d2 = bit skip (0-7).
  518.         sub.b    d2,d1
  519.         lsl.w    d1,d7                ;shift data 0.
  520.         lsl.w    d1,d3                ;shift data 1.
  521.         move.w    d7,d6
  522.         or.w    d3,d6
  523.         eor.w    #$ffff,d6
  524.  
  525.         and.w    d6,(a4)
  526.         or.w    d7,(a4)
  527.         add.l    #40,a4
  528.         and.w    d6,(a4)
  529.         or.w    d3,(a4)
  530.  
  531.         and.w    d6,(a5)
  532.         and.w    d6,40(a5)
  533.  
  534. aga_next_spr:    dbra    d0,sspr_aga_c8xq        ;next sprite.
  535. aga_spr_exit:    rts
  536.